package com.example.database_manage.student;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.example.database_manage.R;
import com.example.database_manage.database.CommonDatabase;

/*
    我的信息功能实现，主要根据登录时传过来的intent所携带的数据
 */
public class about_me extends AppCompatActivity {
    SQLiteDatabase db;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about_me);

        //获取数据库对象
        db = new CommonDatabase().getSqliteObject(about_me.this, "test_db");

        //获取登录时传来的信息
        final Intent intent_about_me = getIntent();

        //绑定组件
        TextView s_about_id = findViewById(R.id.aboutme_id);
        TextView s_about_name = findViewById(R.id.aboutme_name);
        TextView s_about_sex = findViewById(R.id.aboutme_sex);
        TextView s_about_age = findViewById(R.id.aboutme_age);
        TextView s_about_class = findViewById(R.id.aboutme_class);
        TextView s_about_birth = findViewById(R.id.aboutme_birth);
        TextView s_about_clubInfo = findViewById(R.id.aboutme_clubInfo);
        TextView s_about_awards = findViewById(R.id.aboutme_awards);
        TextView s_about_work = findViewById(R.id.aboutme_work);

        @SuppressLint("Recycle") Cursor cursor_about = db.query("student", null, "id = ?", new String[]{intent_about_me.getStringExtra("student_id")}, null, null, null);
        while (cursor_about.moveToNext()) {
            //将通过id查询到的学生信息显示到界面中
            s_about_id.setText(cursor_about.getString(cursor_about.getColumnIndex("id")));
            s_about_name.setText(cursor_about.getString(cursor_about.getColumnIndex("sname")));
            s_about_sex.setText(cursor_about.getString(cursor_about.getColumnIndex("sex")));
            s_about_age.setText(cursor_about.getString(cursor_about.getColumnIndex("age")));
            s_about_class.setText(cursor_about.getString(cursor_about.getColumnIndex("classroom")));
            s_about_birth.setText(cursor_about.getString(cursor_about.getColumnIndex("birth")));
            s_about_clubInfo.setText(cursor_about.getString(cursor_about.getColumnIndex("clubInfo")));
            s_about_awards.setText(cursor_about.getString(cursor_about.getColumnIndex("awards")));
            s_about_work.setText(cursor_about.getString(cursor_about.getColumnIndex("graduationWork")));


        }
        Button button_back = findViewById(R.id.button_finish_about);


        button_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}
